/*
 *  vbe.c
 *  xcode
 *
 *  Created by Emiel Goor,van on 28-01-08.
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
 *
 */

#include "vbe.h"
#include "common.h"
unsigned char *VGA = (unsigned char *)0xE0000;
unsigned char *dbl_buffer;
void init_dbl_buffer(void)
{
    dbl_buffer = (unsigned char *) kmalloc (SCREEN_WIDTH * SCREEN_HEIGHT);
    if (dbl_buffer == NULL)
    {
		printf("Not enough memory for double buffer.\n");
    }
}

void update_screen(void)
{
    #ifdef VERTICAL_RETRACE
      while ((inportb(0x3DA) & 0x08));
      while (!(inportb(0x3DA) & 0x08));
    #endif
    memcpy(VGA, dbl_buffer, (unsigned int)(SCREEN_WIDTH * SCREEN_HEIGHT));
}

void setpixel (BITMAP *bmp, int x, int y, unsigned char color)
{
    bmp->data[y * bmp->width + x];
}

void vbeinit(unsigned long *framebuffer)
{
//	*VGA = framebuffer;
	
	printf("VBE INIT\n");
	init_dbl_buffer();
	memset (dbl_buffer, 2, SCREEN_WIDTH * SCREEN_HEIGHT);
	 setpixel (dbl_buffer, 10, 10, 10);
	update_screen();
}
